function openFile(fileInfo){
	cleanContent($('workTd'));//清理主面板内容
	SYS_STATUS.isTemplate=false;//是否是模板编模式 
	this.fileInfo=fileInfo;
	this.formTagBar=$C('div',{'id':'formTagBar'});
	this.tableDiv=$C('div',{'id':'tableDiv'});
	this.xmlPath='db/budget/';
}
openFile.prototype={
	workTd:'',
	formsList:'',
	formsNum:'',
	flag:0,
	init:function(){
		freeRam();
		SYS_STATUS.loading();
		removeClass(SYS_STATUS.currentMenu,'using');//取消使用标志
		SYS_STATUS.currentMenu=null;//取消menu禁用
		this.flag=0;
		this.workTd=$('workTd');
		this.makeInfoBar();
		this.makeContrlBar();
		SYS_STATUS.fileInfo=this.fileInfo;
		this.workTd.appendChild(this.formTagBar);
		ajax.get('book/'+this.fileInfo.tempno+'_template.xml',function(formsXml){
			this.formsList=formsXml.getElementsByTagName('sheet');
			this.formsNum=this.formsList.length;
			this.loadForm(0);
		}.bind(this));
	},
	loadForm:function(){
		if(this.formsNum==this.flag){
			this.formTagBar.appendChild($C('div',{'class':'clear'}));
			this.formTagBar.className='formTagBarBg';
			this.currentTag=this.formTagBar.firstChild.nextSibling;
			addClass($('tag_'+this.formsList[0].getAttribute('id')),'formTag_use');//this.formsList[0].getAttribute('id')是第一表格的ID
			this.workTd.appendChild(this.tableDiv);
			removeClass(this.tableDiv.firstChild,'hide');
			//alert(this.tableDiv.firstChild.className);
			SYS_STATUS.currentTable=this.tableDiv.firstChild.id;
			this.parserFormFormula();
			return;
		}
		//SYS_STATUS.table
		this.formTagBar.appendChild(this.makeTag());
  		ajax.get(this.xmlPath+this.fileInfo.filename+'/'+this.formsList[this.flag].getAttribute('xmlfile')+'.xml',this.reGetXml.bind(this));		
	},
	reGetXml:function(xmlForm){
		this.tableDiv.appendChild($C('div',{'id':this.formsList[this.flag].getAttribute('id'),'class':'hide'},(new makeTable(xmlForm,this.formsList[this.flag].getAttribute('id'))).init()));
		this.loadForm(++this.flag);
	},
	makeInfoBar:function(){
		var infoBar=$C('div',{'class':'innerDiv','id':'infoBar'},$C('div',{'id':'fileInfo'},$C('span',{},'井号:'),$C('span',{'class':'nextitem'},''+this.fileInfo.wellno),$C('span',{},'创建者:'),$C('span',{'class':'nextitem'},this.fileInfo.author),$C('span',{},'创建时间:'),$C('span',{'class':'nextitem'},this.fileInfo.createdate),$C('span',{},'状态:'),$C('span',{'id':'infobar_status','class':'nextitem'},fixStatus[this.fileInfo.status])),$C('div',{'id':'statusBar'}));
		infoBar.appendChild($C('div',{'class':'clear'}));
		this.workTd.appendChild(infoBar);
	},
	makeTag:function(){
		var tmpTag=$C('span',{'class':'formTag'},this.formsList[this.flag].getAttribute('shortName'));
		tmpTag.relation=this.formsList[this.flag].getAttribute('id');
		tmpTag.id='tag_'+tmpTag.relation;
		tmpTag.isUse=false;
		eve.observe(tmpTag,'click',this.clickTag.bind(this));
		return tmpTag;
	},
	commitFile:function(){
		if('commit'==this.fileInfo.status)	return
		if(false==confirm('文件提交后，除非未通过审核，否则将不能再修改。\n你确定要提交'+SYS_STATUS.fileInfo.wellno+'?'))	return;
		closeEditPanel();//如果输入框还在显示，则关闭
		saveBudget();//如果有新数据，则保存
		ajax.post('utils/file.php',postParam('changeatt',{'attrs':{'status':'commit'},'wellno':SYS_STATUS['fileInfo']['wellno']}),function(result){
			var re=parseJson(result);
			if(re.result!=1)
				showmsg('提交失败,原因是'+re.reason);
			else{
				showStatus('文件“'+SYS_STATUS['fileInfo']['wellno']+'”已经提交，请等待审核结果');
				changeStatusDis('commit');
				addClass($('committag'),'forbid');//鼠标移上去显示禁止
				this.fileInfo.status='commit';
				closeEdit();//使单元格不可编辑
				showMessage();
			}
		}.bind(this));
	},
	makeContrlBar:function(){
		var contrlDiv=$C('div',{'id':'contrlbar'});
		var saveTag=$C('span',{'id':'savetag'},'保存');
		var commitTag=$C('span',{'id':'committag'},'提交');
		var printTag=$C('span',{'id':'printtag'},'打印');
		var checkTag=$C('span',{'id':'checktag'},'审核');
		eve.observe(saveTag,'click',saveBudget);
		contrlDiv.appendChild(saveTag);
		if('commit'==this.fileInfo.status){//如果是已经提交的文件,管理员可以审核
			if(isAdmin()){
				eve.observe(checkTag,'click',this.checkFile.bind(this));
				contrlDiv.appendChild(checkTag);
			}
		}
		else if('freeze'!=this.fileInfo.status){//已经通过审核的文件只能管理员可以打开
			eve.observe(commitTag,'click',this.commitFile.bind(this));
			contrlDiv.appendChild(commitTag);
		}
		eve.observe(printTag,'click',this.printBudget);
		contrlDiv.appendChild(printTag);
		this.formTagBar.appendChild(contrlDiv)
	},
	printBudget:function(){
		//return unusable();
		var printList=$C('div',{'id':'printList'});	
		for(var t in TABLES){
			if('beforecalc'==t||'acidcalc'==t)	continue;//修计 酸计 不打印
			removeClass($(t),'printTable');//清除之前打印过的选择
			printList.appendChild($C('div',{},'<input type="checkbox" id="print'+t+'" checked="true"/> <label for="print'+t+'"> '+TABLES[t].table.caption.innerHTML+'</label>'));
		}
		var selectBtn=$C('input',{'type':'button','class':'btn','value':'下一步'});
		var closeBtn=$C('input',{'type':'button','class':'btn','value':'关闭'});
		eve.observe(selectBtn,'click',function(){
			for(var t in TABLES){
				if('beforecalc'==t||'acidcalc'==t)	continue;//修计 酸计
				if($('print'+t).checked){
					addClass($(t),'printTable');//要打印的table,
					//alert(TABLES[t].table.className);
				}
			}
			w();//关闭选择打印表的对话框;
			var printBtn=$C('input',{'type':'button','class':'btn','value':'打印'});
			eve.observe(printBtn,'click',function(){
				psbirdDialog.success('打印开始,如果你的打印机还没有开始工作,请检查打印机设置是否正常');
				window.print();
			});
			psbirdDialog.html($C('div',{},'<br/>系统的打印功能用的是浏览器自带的打印功能.如果您想看打印效果,请在浏览器菜单栏点<span class="red">文件</span>-&gt;<span class="red">打印预览</span>,<br/><br/>您也可以使用<span class="red">页面设置</span>来改变打印效果.确保一切就绪后再打印.<br/><br/>',$C('div',{'class':'cen'},printBtn)),300,'打印概算');
		});
		var w=psbirdDialog.html($C('div',{},$C('div',{'class':'cen'},' <br/>请选择你要打印的表格.'),printList,$C('div',{'class':'green cen'},'<br/>'),$C('div',{'class':'cen'},selectBtn,closeBtn)),350,'打印概算');
		eve.observe(closeBtn,'click',w);//关闭窗口
	},
	switchTag:function(obj){
		if(true==obj.isUse)	return;
		if(true==SYS_STATUS.isEditing)	TABLES[SYS_STATUS.currentTable].editEnd();
		if(false!=SYS_STATUS.selectCell)	SYS_STATUS.editPanel.className='hide';
		SYS_STATUS.selectCell=false;
		this.currentTag.isUse=false;
		removeClass(this.currentTag,'formTag_use');//.className=self.currentTag.className.replace(' ','');
		addClass($(this.currentTag.relation),'hide');
		addClass(obj,'formTag_use');
		removeClass($(obj.relation),'hide');
		this.currentTag=obj;
		SYS_STATUS.currentTable=obj.relation;
		obj.isUse=true;
	},
	clickTag:function(e){
		this.switchTag(e.target||e.srcElement);
	},
	checkFile:function(){
		if('commit'!=this.fileInfo.status)	return//已经审核过了就不能再审核
		var isPass=$C('input',{'type':'checkbox','id':'checkResult'});
		var ok=$C('input',{'type':'button','class':'btn','value':'确定'});
		var cancel=$C('input',{'type':'button','class':'btn','value':'关闭'});
		eve.observe(isPass,'click',function(e){
			var box=e.target||e.srcElement;
			//debug(box.isChecked);
			if(true==box.checked){
				$('dispResult').firstChild.innerHTML='通过审核';
				$('rejectReason').className='hide';
			}else{
				$('dispResult').firstChild.innerHTML='拒绝通过';
				$('rejectReason').className='cen';
			}
		});
		var reason=$C('div',{'id':'rejectReason','class':'hide'},$C('span',{},'请输入拒绝通过的原因：<br/><br/>'),$C('textarea',{'id':'reasonInput','rows':'6','cols':'40'}),$C('br',{}),$C('br',{}));
		eve.observe(ok,'click',function(){
			if(false==isPass.checked){
				if(false==confirm('你拒绝该概算文件通过审核,确定吗?'))	return;
				if(''==$('reasonInput').value.trim())	return alert('请输入拒绝通过审核的原因.');
			}
			ajax.post('utils/file.php',postParam('check',{'wellno':SYS_STATUS.fileInfo.wellno,'result':isPass.checked,'reason':(isPass.checked)?'':$('reasonInput').value}),function(result){
				var re=parseJson(result);
				if(1!=re.result)	return showmsg('操作不成功：原因是 '+re.reason);
				if(true==isPass.checked){
					this.fileInfo.status='freeze';

				}else{
					this.fileInfo.status='reject';
				}
				showMessage();
				changeStatusDis(this.fileInfo.status);
				showStatus('操作成功');
				addClass($('checktag'),'forbid');//鼠标移上去显示禁止
				m();//关闭窗口
			}.bind(this));
		}.bind(this));
		var m=psbirdDialog.html($C('div',{'id':'checkDiv'},$C('div',{'class':'cen'},$C('span',{},'<br/>审核结果: '),$C('span',{}),$C('span',{},isPass,$C('span',{'class':'red bold','id':'dispResult'},'<label for="checkResult">通过审核</label>'),$C('span',{},'(选中表示通过审核)<br/><br/>'))),reason,$C('div',{'class':'cen'},ok,cancel)),300,'审核概算');
		isPass.checked=true;//在IE浏览器下必须写在这里.
		eve.observe(cancel,'click',m);
	},
 	parserFormFormula:function(){
		var l,formulaObj;
		//var date1=new Date();debug(date1.getHours()+':'+date1.getMinutes()+':'+date1.getSeconds()+':'+date1.getMilliseconds()+'<br/>');
		for(var tableId in TABLES){
			formulaObj=TABLES[tableId].formulas;
			for(var f in formulaObj){
				(new treatFormula(tableId,f,formulaObj[f])).init();
			}
			/*打印单元格连动性
			for(var c in TABLES[tableId]['cell']){
				var cell=TABLES[tableId]['cell'];
				if(cell[c].editType>0){
					if(TABLES[tableId]['relations'][c].length>0)
						this.debugFormula('$'+tableId+'_'+c,document.body);
				}
			}//*/
			/*调试初始计算公式
			var vars=TABLES[tableId]['vars'];
			for(v in vars){
				if(true==this.checkVars(vars[v])){
					debug(tableId+'_'+v+':'+vars[v]+'<br/><br/>');
				}
			}
			//*/
		}
		//var date2=new Date();debug(date2.getHours()+':'+date2.getMinutes()+':'+date2.getSeconds()+':'+date2.getMilliseconds()+'<br/>');
		/*
		this.debugFormula('$period_C3',document.body);
		(new parseFormula).init(['$period_C3']);
		//*/
		//*如果不是从缓存里取得，则初始化计算
		//debug(0==this.fileInfo.iscache);
		if(0==this.fileInfo.iscache)	initCalculate();
		SYS_STATUS.loadComplete();//加载完成
		//*/
	/*打印单元格连动性所用到的函数
	},
 	lineNum:0,
	debugFormula:function(cellNo,pNode){
		var tmpCellName=getCellName(cellNo),tmpC;
		var tmpRe=TABLES[tmpCellName[0]]['relations'][tmpCellName[1]];
		for(var i=0;i<tmpRe.length;i++){
			++this.lineNum;
			var node=$C('div',{'class':'debugLine'},cellNo+'=>'+tmpRe[i]+' <span class="red">'+this.lineNum+'</span>');
			tmpC=getCellName(tmpRe[i]);
			if(TABLES[tmpC[0]]['relations'][tmpC[1]].length>0)
				this.debugFormula(tmpRe[i],node);
			pNode.appendChild(node);
		}//*/
	}
}
function isChange(cellNo){
	var tmpCell=getCell(cellNo);
	var oldValue=tmpCell.cellValue;
	(new calculate(cellNo)).init();
	//debug(cellNo+'?'+oldValue+'==>'+tmpCell.cellValue+'<br/>');
	return oldValue==tmpCell.cellValue;
}
function initCalculate(){
	var changeedCells=[],oldValue,tmpCell,tmpRelation,tmpIsIn,tmpResult=[],result=[],l,lj,lk,lm,vars,formulas,cellNo;
	//var date1=new Date();debug(date1.getHours()+':'+date1.getMinutes()+':'+date1.getSeconds()+'<br/>');
	for(var tableId in TABLES){
		formulas=TABLES[tableId]['vars'];
		for(var f in formulas){//把每个一公式都执行一遍主要是因为有的公式有常数 比如F1+5 如果F1=0但执行结果却是5
			cellNo='$'+tableId+'_'+f;
			if(false==isChange(cellNo))	changeedCells.push(cellNo);//如果计算后有改变则加入联动计算
		}
	}
	//var date2=new Date();debug(date2.getHours()+':'+date2.getMinutes()+':'+date2.getSeconds()+'<br/>');
	changeedCells=changeedCells.single();//去掉重覆项
	//debug(changeedCells.length+'<br/>');
	//*
	
	l=changeedCells.length;
	//debug(changeedCells+'<br/>');
	for(var i=0;i<l;i++){
		tmpRelation=(new parseFormula).init(changeedCells[i]);
		lj=tmpRelation.length;
		for(var j=0;j<lj;j++){
			tmpIsIn=tmpResult.isIn(tmpRelation[j]);
			if(-1!=tmpIsIn)	tmpResult[tmpIsIn]=0;
			tmpResult.push(tmpRelation[j]);
		}
	}
	//var date3=new Date();debug(date3.getHours()+':'+date3.getMinutes()+':'+date3.getSeconds()+'<br/>');
	lk=tmpResult.length;
	for(var k=0;k<lk;k++){
		if(0==tmpResult[k])	continue;
		result.push(tmpResult[k]);
	}
	//debug(result.length);
	//debug(result);
	lm=result.length;
	for(var m=0;m<lm;m++){
		(new calculate(result[m])).init();
	}
	if('new'==SYS_STATUS.fileInfo.status){//如果是新建文件 并且不是从cache里读取的
		ajax.post('utils/file.php',postParam('savecache',{'tempno':SYS_STATUS['fileInfo']['tempno'],'pake':makeSavePake()}),function(result){//则生成一个cache，以便以后新建的时候读取cache
			var re=parseJson(result);
			if(re.result==0)	ajax.post('utils/file.php',postParam('delcache',null),emptyFunc);//如果保存不成功，把cache文件里的文件删除
		});
		ajax.post('utils/file.php',postParam('changeatt',{'attrs':{'iscache':'1'},'wellno':SYS_STATUS['fileInfo']['wellno']}),function(result){
			var re=parseJson(result);
			if(re.result==1)	cleanDirtyCell('dirtyCell');
		});//把该文件的iscache属性改为1，以后读取时就不用重新计算了
	}
	//*/
	//debug(result);
	//var date4=new Date();debug(date4.getHours()+':'+date4.getMinutes()+':'+date4.getSeconds()+'<br/>');
}
function listBudget(){}
listBudget.prototype={
	page:0,
	list:[],
	pagecount:0,
	table:{},
	init:function(re){
		cleanContent($('workTd'));//清理面板
		this.page=re.page;
		this.list=re.list;
		this.pagecount=re.pagecount;
		$('workTd').appendChild($C('div',{'class':'innerDiv'},$C('table',{'class':'listtable'},this.makeTable())));
	},
	makeTable:function(){
		var l=this.list.length;
		var fileTbody=$C('tbody',{},$C('tr',{},$C('th',{'width':'20%'},'文件名'),$C('th',{'width':'15%'},'建立者'),$C('th',{'width':'20%'},'建立日期'),$C('th',{'width':'20%'},'当前状态'),$C('th',{'width':'25%'},'操作')));
		if(0==this.pagecount)	return fileTbody.appendChild($C('tr',{},$C('td',{'class':'cen'},'目前没有可用文件')))
		for (var i=0;i<l;i++)
			fileTbody.appendChild(this.makeFileTr(i));
		//alert(fileTbody.innerHTML);
		fileTbody.appendChild(this.makePageInfo());
		return fileTbody;//.appendChild(this.makePageInfo());
	},
	makeFileTr:function(i){
		var item=this.list[i];
		var fileName=$C('td',{'class':'status '+item.status},$C('span',{'class':'click'},item.wellno));
		eve.observe(fileName,'click',displayBudget.bind(item));
		var tr=$C('tr',{},fileName,$C('td',{},item.author),$C('td',{},item.createdate),$C('td',{},fixStatus[item.status]),$C('td',{},this.enableContrl(item.status,item)));
		if(1==i%2)	tr.className='highlight';
		return tr;
	},
	makePageInfo:function(){
		var td=$C('td',{'colspan':'5','class':'right','id':'pageinfo'});
		td.appendChild($C('span',{},'共'+this.pagecount+'页'));
		td.appendChild($C('span',{},'第'+this.page+'页'));
		if(this.pagecount<=1)	return $C('tr',{},td);
		var firstPage=$C('span',{'class':'click'},'首页');
		var nextPage=$C('span',{'class':'click'},'下一页');
		var previousPage=$C('span',{'class':'click'},'上一页');
		var lastPage=$C('span',{'class':'click'},'尾页');
		if(this.page!=1){
			eve.observe(firstPage,'click',this.goToPage.bind(1));
			td.appendChild(firstPage);
		}
		if(this.page!=this.pagecount){
			eve.observe(nextPage,'click',this.goToPage.bind(this.page+1));
			td.appendChild(nextPage);
		}
		if(this.page!=1){
			eve.observe(previousPage,'click',this.goToPage.bind(this.page-1));
			td.appendChild(previousPage);
		}
		if(this.page!=this.pagecount){
			eve.observe(lastPage,'click',this.goToPage.bind(this.pagecount));
			td.appendChild(lastPage);
		}
		var sele=$C('select',{});
		for(var i=1;i<=this.pagecount;i++){
			sele.appendChild(newOption('第'+i+'页',i,i==this.page));
		}
		eve.observe(sele,'change',function(e){var o=e.target||e.srcElement;this.goToPage.apply(o.value)}.bind(this));//主要是this是指的对象经常发生改变
		td.appendChild($C('span',{},sele));
		return $C('tr',{},td);
	},
 	goToPage:function(){
		getList(this);
	},
	enableContrl:function(s,item){//s=status
		var del=$C('span',{'class':'contrl del'},'删除');
		del.item=item;
		var view=$C('span',{'class':'contrl view'},'查看');
		eve.observe(view,'click',displayBudget.bind(item));
		eve.observe(del,'click',this.delFile.bind(this));
		var cont=$C('div',{},view);
		if(canEdit(item))	cont.appendChild(del);//如果有编辑权限，则有删除按钮
		return cont;
	},
	delFile:function(e){
		var obj=e.target||e.srcElement;
		if(false==confirm('你确定要删除文件“'+obj.item.wellno+'”吗?'))	return;
		//return unusable();
		ajax.post('utils/file.php',postParam('delbudget',{'wellno':obj.item.wellno,'filepath':obj.item.filename}),function(result){
			re=parseJson(result);
			if(1==re.result){
				//for(var p in this)	debug(p);
				this.goToPage.apply(this.page);
			}else{
				showmsg(re.reason);
			}
		}.bind(this));
	}
};
function listUser(){}
listUser.prototype={
	list:[],
	table:{},
	fixRole:{'admin':'系统管理员','actor':'操作者'},
	init:function(re){
		cleanContent($('workTd'));//清理面板
		this.list=re;
		$('workTd').appendChild($C('div',{'class':'innerDiv'},$C('table',{'class':'listtable'},this.makeTable())));
	},
	makeTable:function(){
		var l=this.list.length;
		var userTbody=$C('tbody',{},$C('tr',{},$C('th',{'width':'25%'},'姓名'),$C('th',{'width':'30%'},'登录名'),$C('th',{'width':'20%'},'角色'),$C('th',{'width':'25%'},'操作')));
		for (var i=0;i<l;i++)
			userTbody.appendChild(this.makeTr(i));
		var addBtn=$C('input',{'type':'button','value':'新用户','class':'btn'});
		addBtn.item={'userid':0,'name':'','username':'','role':'actor'};//这一步的目的是添加新用户
		eve.observe(addBtn,'click',this.editUser.bind(this));
		userTbody.appendChild($C('tr',{},$C('td',{'colspan':'4','class':'right','id':'pageinfo'},addBtn)));
		return userTbody;//.appendChild(this.makePageInfo());
	},
	makeTr:function(i){
		var item=this.list[i];
		//for(var a in item)debug(a+'=>'+item[a]);
		var tr=$C('tr',{},$C('td',{},item.name),$C('td',{},item.username),$C('td',{},this.fixRole[item.role]),$C('td',{},this.enableContrl(item)));
		if(1==i%2)	tr.className='highlight';
		return tr;
	},
	enableContrl:function(item){
		var del=$C('span',{'class':'contrl del'},'删除');
		del.item=item;
		var edit=$C('span',{'class':'contrl view'},'修改');
		edit.item=item;
		eve.observe(edit,'click',this.editUser.bind(this));
		if(item.userid!=SYS_STATUS.userInfo.userid)
			eve.observe(del,'click',this.delUser.bind(this));
		else
			addClass(del,'forbid');
		return $C('div',{},edit,del);
	},
	editUser:function(e){
		var itemObj=e.target||e.srcElement;
		var titleStr=(0==itemObj.item.userid)?'添加新用户':'编辑用户资料';
		var mForm=$C('ul',{});
		mForm.appendChild($C('li',{'class':'l'},'姓名'));
		mForm.appendChild($C('li',{'class':'r'},$C('input',{'type':'text','name':'name','value':itemObj.item.name})));
		mForm.appendChild($C('li',{'class':'l'},'用户名'));
		mForm.appendChild($C('li',{'class':'r'},$C('input',{'type':'text','name':'username','value':itemObj.item.username})));
		if(0==itemObj.item.userid){
			mForm.appendChild($C('li',{'class':'l'},'密码'));
			mForm.appendChild($C('li',{'class':'r'},$C('input',{'type':'password','name':'passwd'})));
			mForm.appendChild($C('li',{'class':'l'},'密码确认'));
			mForm.appendChild($C('li',{'class':'r'},$C('input',{'type':'password','name':'repwd'})));
		}
		mForm.appendChild($C('li',{'class':'l'},'角色'));
		var selectRole=$C('select');
		for(var p in this.fixRole){
			selectRole.appendChild(newOption(this.fixRole[p],p,p==itemObj.item.role));
		}
		mForm.appendChild($C('li',{'class':'r'},selectRole));
		var okBtn=$C('input',{'type':'button','class':'btn','value':'提交'});
		eve.observe(okBtn,'click',function(){
			var data={};
			var input=mForm.getElementsByTagName('input');
			data.role=selectRole.value;
			for(var i=0;i<input.length;i++){
				if(''==input[i].value.length)	return alert('数据不完整');
				data[input[i].name]=input[i].value;
			}
			if(0==itemObj.item.userid){
				if(data.passwd.length<5)	return alert('密码长度不能小于5位');
				if(data.passwd!=data.repwd)	return alert('两次填写的密码不一样');
			}
			w();//关闭窗口
			ajax.post('utils/user.php',postParam('edituser',{'userid':itemObj['item']['userid'],'data':data}),function(result){
				var re=parseJson(result);
				if(0==re.result)	return alert(re.reason);
				manageUser();//刷新列表
			});
		});
		var closeBtn=$C('input',{'type':'button','class':'btn','value':'取消'});
		var w=psbirdDialog.html($C('div',{},$C('div',{},'<span class="red">注意:姓名是真实姓名,用户名是登录时填写的登录名.密码必须5位以上</span>'),$C('div',{'class':'modifyForm'},mForm,$C('div',{'class':'clear'})),$C('div',{'class':'cen'},okBtn,closeBtn)),400,titleStr);
		eve.observe(closeBtn,'click',w);
	},
	delUser:function(e){
		itemObj=e.target||e.srcElement;
		if(!confirm('你确定删除用户 '+itemObj.item.name+' 吗'))	return;
		ajax.post('utils/user.php',postParam('deluser',{'userid':itemObj.item.userid}),function(result){
			var re=parseJson(result);
			if(1!=re.result)	return showmsg('未知错误');
			manageUser();
		});
	}
};
function listTemplate(){}
listTemplate.prototype={
	list:[],
	table:null,
	init:function(re){
		cleanContent($('workTd'));//清理面板
		this.list=re;
		$('workTd').appendChild($C('div',{'class':'innerDiv'},$C('table',{'class':'listtable'},this.makeTable())));
	},
	makeTable:function(){
		var l=this.list.length;
		var tempTbody=$C('tbody',{},$C('tr',{},$C('th',{'width':'40%'},'模板名称'),$C('th',{'width':'30%'},'模板路径'),$C('th',{'width':'30%'},'操作')));
		for (var i=0;i<l;i++)
			tempTbody.appendChild(this.makeTr(i));
		return tempTbody;//.appendChild(this.makePageInfo());
	},
	makeTr:function(i){
		var item=this.list[i];
		var tr=$C('tr',{},$C('td',{},item.name),$C('td',{},item.shortname),$C('td',{},this.enableContrl(item)));
		if(1==i%2)	tr.className='highlight';
		return tr;
	},
	enableContrl:function(item){
		var edit=$C('span',{'class':'contrl edittemp'},'编辑');
		edit.item=item;
		eve.observe(edit,'click',displayTemplate.bind(item));
		return $C('div',{},edit);
	}
};
function displayTemplate(){
	//alert(this.shortname);
	(new editTemplate(this)).init();
}
function editTemplate(fileInfo){
	//for(var m in fileInfo)	debug(fileInfo);
	//alert(fileInfo.tempno);
	cleanContent($('workTd'));//清理主面板内容 
	SYS_STATUS.isTemplate=true;//是否是模板编模式
	this.fileInfo=fileInfo;
	this.fileInfo.tempno=fileInfo.shortname;//加上tempno是为了和前面代码的兼容
	this.fileInfo.filename='';//加上filename是为了和前面代码的兼容
	this.formTagBar=$C('div',{'id':'formTagBar'});
	this.tableDiv=$C('div',{'id':'tableDiv'});
	this.xmlPath='book/'+fileInfo.shortname;
	SYS_STATUS.tableName={};
	//alert(this.xmlPath);
}
Object.extend(Object.extend(editTemplate.prototype,openFile.prototype),{
	loadForm:function(){
		if(this.formsNum==this.flag){
			this.formTagBar.appendChild($C('div',{'class':'clear'}));
			this.formTagBar.className='formTagBarBg';
			this.currentTag=this.formTagBar.firstChild.nextSibling;
			addClass($('tag_'+this.formsList[0].getAttribute('id')),'formTag_use');
			this.workTd.appendChild(this.tableDiv);
			removeClass(this.tableDiv.firstChild,'hide');
			//alert(this.tableDiv.firstChild.className);
			SYS_STATUS.currentTable=this.tableDiv.firstChild.id;
			SYS_STATUS.loadComplete();
			return;
		}
		SYS_STATUS.tableName[this.formsList[this.flag].getAttribute('id')]=this.formsList[this.flag].getAttribute('shortName');
		this.formTagBar.appendChild(this.makeTag());
  		ajax.get(this.xmlPath+this.fileInfo.filename+'/'+this.formsList[this.flag].getAttribute('xmlfile')+'.xml',this.reGetXml.bind(this));		
	},
	makeInfoBar:function(){
		var infoBar=$C('div',{'class':'innerDiv'},$C('div',{'id':'infoBar'}));
		infoBar.appendChild($C('div',{'class':'clear'}));
		this.workTd.appendChild(infoBar);
	},
	makeContrlBar:function(){
		var contrlDiv=$C('div',{'id':'contrlbar'});
		var saveTag=$C('span',{'id':'savetag'},'保存');
		eve.observe(saveTag,'click',this.saveBook.bind(this));
		contrlDiv.appendChild(saveTag);
		this.formTagBar.appendChild(contrlDiv)
	},
	reGetXml:function(xmlForm){
		this.tableDiv.appendChild($C('div',{'id':this.formsList[this.flag].getAttribute('id'),'class':'hide'},(new editTable(xmlForm,this.formsList[this.flag].getAttribute('id'))).init()));
		this.loadForm(++this.flag);
	},
	saveBook:function(){
		var d,savePack={},tmpCell;
		if(true==SYS_STATUS.isEditing)	TABLES[SYS_STATUS.currentTable].editEnd();//如果有单元格正在编辑
		//debug(this.isNeedSave());
		if(false==this.isNeedSave())	return alert('没有任何改动');
		if(false==confirm('模板文件已经改动,你确定要保存到服务器?'))	return;
		for(var t in TABLES){
			if(false==TABLES[t].isDirtyTemplate())	continue;
			savePack[t]={};
			d=TABLES[t].dirtyFormula;
			for(var i=0;i<d.length;i++){
				savePack[t][d[i]]={};
				var tmpObj={};
				tmpCell=getCell('$'+t+'_'+d[i]);
				savePack[t][d[i]]['cellType']=tmpCell.cellType;
				savePack[t][d[i]]['editType']=tmpCell.editType;
				savePack[t][d[i]]['initValue']=tmpCell.initValue.replace(/\+/g,'#');
			}
		}
	//	alert(fileInfo.tempno);
		ajax.post('utils/template.php?action=savetemplate',postParam('',{'templateno':this.fileInfo['tempno'],'savePack':savePack}),function(result){
			if(1==parseJson(result).result){
				cleanDirtyCell('dirtyFormula');
			}else{
				alert('未知错误,请联系管理员');
			}
		});
	},
	isNeedSave:function(){
		for(var t in TABLES){
			if(false==TABLES[t].isDirtyTemplate())	continue;
			return true;
		}
		return false;
	}
});
function parseRss(rssFeed){
	this.rssFeed=rssFeed;
}
parseRss.prototype={
	rssTitle:'',
	rssItems:[],
	init:function(){
		this.container=$('messageList');
		ajax.get(this.rssFeed,this.parseRss.bind(this));
	},
	parseRss:function(rssXml){
		this.rssTitle=rssXml.getElementsByTagName('title')[0].firstChild.data;
		this.rssItems=rssXml.getElementsByTagName('item');
		this.container.appendChild(this.makeTitle());
		this.container.appendChild(this.makeList());
	},
	makeTitle:function(){
		return $C('div',{'class':'cen bold messagetitle'},this.rssTitle);
	},
	makeList:function(){
		var l=this.rssItems.length;
		var list=$C('div',{});
		for(var i=l-1;i>=0;i--){
			//if(this.dispalyNum==c++)	break;//如果已经达到最大显示数，则退出循环	
			list.appendChild(this.makeItem(this.rssItems[i]));
		}
		return list;
	},
	makeItem:function(item){
		var itemTitle=item.getElementsByTagName('title')[0].firstChild.data;
		var itemDiv=$C('div',{'class':'item click','title':item.getElementsByTagName('description')[0].firstChild.data},'·'+itemTitle);
		eve.observe(itemDiv,'click',this.showItem.bind(item));
		return itemDiv
	},
	showItem:function(){
		psbirdDialog.alert(this.getElementsByTagName('description')[0].firstChild.data+'<br/>时间：'+this.getElementsByTagName('pubdate')[0].firstChild.data);
	}
};